package com.cetc39.action;

import java.util.ArrayList;
import java.util.List;

import com.cetc39.bean.Client;
import com.cetc39.service.ClientService;
import com.cetc39.util.StringUtil;
import com.opensymphony.xwork2.ActionSupport;

public class ClientAction extends ActionSupport {

	private ClientService clientService;
	private List<?> clientList;
	private Client client;
	private String opcode;
	private int id;
	
	public String getAllClient() {
		clientList = clientService.findAll();
		if("alllist_for_detail".equals(opcode)) {
			return "alllist_for_detail";
		} else if("alllist_for_project".equals(opcode)) {
			return "alllist_for_project";
		}
		return SUCCESS;
	}
	
	public String addClient() {
		String abbr = StringUtil.getFirstLetter(client.getName());
		client.setAbbr(abbr);
		client.setAdminmanagerl("");
		client.setManager("");
		client.setPlanmanager("");
		client.setTeacmanager("");
		client.setUpdept("");
		clientService.add(client);
		opcode = "alllist_for_detail";
		return SUCCESS;
	}
	
	public String deleteClient() {
		clientService.delete(id);
		return SUCCESS;
	}
	
	public List<?> getClientList() {
		return clientList;
	}

	public void setClientList(List<?> clientList) {
		this.clientList = clientList;
	}

	public void setClientService(ClientService clientService) {
		this.clientService = clientService;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public String getOpcode() {
		return opcode;
	}

	public void setOpcode(String opcode) {
		this.opcode = opcode;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

}
